package com.hbnu.system.controller;


import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.TranProjectTSdto;
import com.hbnu.system.model.dto.Tranproject_registrationDTO;
import com.hbnu.system.model.entity.Tranproject_registration;
import com.hbnu.system.model.entity.Tranprojectfile;
import com.hbnu.system.model.query.TranProjectExportQuery;
import com.hbnu.system.model.query.TranProjectPageQuery;
import com.hbnu.system.model.vo.ExportTranProjectVO;
import com.hbnu.system.service.ITranproject_registrationService;
import com.hbnu.system.service.IPorproject_registrationService;
import com.hbnu.system.service.TranprojectfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/tranproject_registration")
@Api(tags = "横向项目模块")
public class Tranproject_registrationController {

    @Autowired
    private ITranproject_registrationService iTranproject_registrationService;
    @Autowired
    private IPorproject_registrationService iPorproject_registrationService;
    @Autowired
    private TranprojectfileService tranprojectfileService;

    @ApiOperation("横向项目-录入")
    @PostMapping("/AddHxProject")
    public Rest<Boolean> AddHxProject(@RequestBody @Valid Tranproject_registrationDTO tranprojectRegistrationDTO){
        boolean add = iTranproject_registrationService.addTranproject(tranprojectRegistrationDTO);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目-删除")
    @GetMapping("/DeleteHxProject")
    public Rest<Boolean> DeleteHxProject(String TRegistrationID) throws IOException {
        boolean delete = iTranproject_registrationService.deleteTranproject(TRegistrationID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目-修改")
    @PostMapping("/UpdateHxProject")
    public Rest<Boolean> UpdateHxProject(@RequestBody @Valid Tranproject_registrationDTO tranprojectRegistrationDTO){
        boolean update = iTranproject_registrationService.updateTranproject(tranprojectRegistrationDTO);
        return update ? Rest.success() : Rest.failed();
    }


    @ApiOperation("根据主键横向项目查询")
    @GetMapping("/GetHxProjectDTOById")
    public Rest<Tranproject_registration> GetHxProjectDTOById(String projectID){
        Tranproject_registration tranprojectdto = iTranproject_registrationService.getTranprojectDTOByID(projectID);
        return Rest.success(tranprojectdto);
    }

    @ApiOperation("横向项目在研申请-提交")
    @GetMapping("/CommitHxProject")
    public Rest<Boolean> CommitHxProject(String tranprojectID){
        Boolean commit = iTranproject_registrationService.CommitTranproject(tranprojectID);
        return commit ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目在研-院级通过")
    @GetMapping("/CollegePassHxProject")
    public Rest<String> CollegePassHxProject(@RequestHeader("X-Token") String token, String tranprojectID){
        Boolean b = iTranproject_registrationService.collegeCheckPass(token, tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目在研-院级退回")
    @PostMapping("/CollegeBackHxProject")
    public Rest<String> CollegeBackHxProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iTranproject_registrationService.collegeCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("暂存横向项目数据")
    @PostMapping("/saveDraftTranProject")
    public Rest<Boolean> saveDraftTranProject(@RequestBody TranProjectTSdto tranProjectTSdto){
        boolean result = iTranproject_registrationService.saveDraftTranProject(tranProjectTSdto);
        return result ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目结题-提交")
    @GetMapping("/CommitFinishHxProject")
    public Rest<Boolean> CommitFinishHxProject(String tranprojectID){
        Boolean commit = iTranproject_registrationService.CommitTranprojectFinish(tranprojectID);
        return commit ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目结题-院级通过")
    @GetMapping("/CollegeFinishPassHxProject")
    public Rest<String> CollegeFinishPassHxProject(@RequestHeader("X-Token") String token, String tranprojectID){
        Boolean b = iTranproject_registrationService.collegeFinishCheckPass(token, tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目结题-院级退回")
    @PostMapping("/CollegeFinishBackHxProject")
    public Rest<String> CollegeFinishBackHxProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iTranproject_registrationService.collegeFinishCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目在研-校级通过")
    @GetMapping("/SchoolPassHxProject")
    public Rest<String> SchoolPassHxProject(@RequestHeader("X-Token") String token,String tranprojectID){
        Boolean b = iTranproject_registrationService.schoolCheckPass(token,tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目在研-校级退回")
    @PostMapping("/SchoolBackHxProject")
    public Rest<String> SchoolBackIdentify(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iTranproject_registrationService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目结题-校级通过")
    @GetMapping("/SchoolFinishPassHxProject")
    public Rest<String> SchoolFinishPassHxProject(@RequestHeader("X-Token") String token,String tranprojectID){
        Boolean b = iTranproject_registrationService.schoolFinishCheckPass(token,tranprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目结题-校级退回")
    @PostMapping("/SchooFinishlBackHxProject")
    public Rest<String> SchooFinishlBackHxProject(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iTranproject_registrationService.schoolFinishCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("用户获取自身项目-分页——产学合作育人")
    @PostMapping("/userGetProjects")
    public Rest<CommonPage<Tranproject_registration>> userGetProjects(@RequestBody TranProjectPageQuery tranProjectPageQuery){
        CommonPage<Tranproject_registration> tranprojectRegistrationCommonPage = iTranproject_registrationService.userGetProjects(tranProjectPageQuery);
        return Rest.success(tranprojectRegistrationCommonPage);
    }


    @ApiOperation("横向项目导出文件")
    @PostMapping("/export")
    public Rest<CommonPage<Tranproject_registration>> export(@RequestBody TranProjectPageQuery tranProjectPageQuery){
        CommonPage<Tranproject_registration> tranprojectRegistrationCommonPage = iTranproject_registrationService.export(tranProjectPageQuery);
        return Rest.success(tranprojectRegistrationCommonPage);
    }
    
    @ApiOperation("横向项目撤回")
    @GetMapping("/WithdrawHxProject")
    public Rest<Boolean> WithdrawHxProject(@RequestHeader("X-Token") String token, String tranprojectID){
        Boolean withdraw = iTranproject_registrationService.withdrawHxProject(token, tranprojectID);
        return withdraw ? Rest.success() : Rest.failed();
    }

    @ApiOperation("横向项目导出文件——最新版")
    @PostMapping("/exportTranProject")
    public Rest<List<ExportTranProjectVO>> exportTranProject(@RequestBody TranProjectExportQuery tranProjectExportQuery){
        List<ExportTranProjectVO> exportTranProjectVOList = iTranproject_registrationService.exportTranProject(tranProjectExportQuery);
        return Rest.success(exportTranProjectVOList);
    }


    @ApiOperation("横向项目-文件信息上传")
    @PostMapping("/addtranprojectfile")
    public Rest<Boolean> addtranprojectfile(@RequestBody Tranprojectfile tranprojectfile){
        boolean add = tranprojectfileService.addTranprojectfile(tranprojectfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("横向项目-文件信息删除")
    @GetMapping("/Deletetranprojectfile")
    public Rest<Boolean> Deletetranprojectfile(String id) throws IOException {
        boolean delete = tranprojectfileService.deletTranprojectfile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("横向项目-文件信息分页查询")
    @GetMapping ("/pagetranprojectfileCondition")
    public Rest<List<Tranprojectfile>> pagetranprojectfileConditionfile(String id){
        List<Tranprojectfile> page = tranprojectfileService.pageTranprojectfile(id);
        return Rest.success(page);
    }
    @ApiOperation("横向项目-文件信息修改")
    @PostMapping("/updatepaperfile")
    public Rest<Boolean> updatetranprojectfile(@RequestBody Tranprojectfile tranprojectfile){
        boolean update = tranprojectfileService.updateTranprojectfile(tranprojectfile);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-院级通过")
    @GetMapping("/CollegePassZxProject")
    public Rest<String> CollegePassZxProject(@RequestHeader("X-Token") String token, String porprojectID){
        Boolean b = iPorproject_registrationService.collegeCheckPass(token, porprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目在研-院级退回")
    @PostMapping("/CollegeBackZxProject")
    public Rest<String> CollegeBackZxProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.collegeCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("纵向项目结题-院级通过")
    @GetMapping("/CollegeFinishPassZxProject")
    public Rest<String> CollegeFinishPassZxProject(@RequestHeader("X-Token") String token, String porprojectID){
        Boolean b = iPorproject_registrationService.collegeFinishCheckPass(token, porprojectID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("纵向项目结题-院级退回")
    @PostMapping("/CollegeFinishBackZxProject")
    public Rest<String> CollegeFinishBackZxProject(@RequestHeader("X-Token") String token, @RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPorproject_registrationService.collegeFinishCheckBack(token, checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
}

